package com.xioaye.cs.basic;
//
//题目描述
//        牛牛有两个长度为nn的数组a, ba,b，牛牛希望统计有多少数对(l, r)(l,r)满足：
//        1，0 \leq l \leq r \leq n - 10≤l≤r≤n−1
//        2，\sum_{i= l}^{r}{a_i} = b_l + b_r∑
//        i=l
//        r
//        ​
//        a
//        i
//        ​
//        =b
//        l
//        ​
//        +b
//        r
//        ​

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;

public class shuzuqiuhetongji {

    public static void main(String[] args) {


//        int[] a= {0,0,1,1,1};
//        int[] b= {2,0,4,3,3};

        int[] a= {83,50,2,41,89,3,98,28,58,17,27,8,94,87,55,91,59,58,23,20,27,75,54,5,88,95,71,51,30,5,67,53,44,23,5,84,56,45,88,50,18,1,16,35,12,85,82,39,61,89,43,90,82,6,25,15,68,32,43,28,93,97,91,28,86,75,71,22,66,94,25,75,34,31,30,92,67,6,56,93,7,42,48,51,12,16,45,63,64,11,22,13,51,95,64,61,32,25,34,42,77,20,7,70,90,28,96,31,74,81,39,53,82,33,57,14,31,63,69,9,24,41,26,47,82,59,1,77,91,81,9,47,28,9,81,19,27,22,90,16,37,27,38,0,16,58,14,43,2,29,1,97,41,80,27,55,81,94,71,47,22,63,28,28,7,0,44,94,27,67,76,0,40,75,82,33,27,65,8,18,42,74,30,55,62,75,43,14,57,58,24,63,65,44,72,54,23,10,74,80,0,98,31,82,20,9,78,32,14,51,77,67,13,76,94,60,15,47,76,15,69,93,94,29,44,47,8,47,94,77,69,44,62,0,82,46,91,93,85,30,29,63,15,3,97,97,15,39,12,9,81,99,60,23,32,70,67,8,16,9,30,55,76,74,19,72,73,25,28,43,46,73,69,97,94,57,57,16,65,37,50,54,58,92,93,54,70,57,95,19,96,31,87,47,24,71,57,65,1,1,76,28,18,27,85,2,4,74,42,93,30,12};
        int[] b= {1160,1041,484,984,163,1029,1484,1802,43,1795,1776,219,1714,561,1159,1853,1704,382,1489,854,119,200,717,1040,1992,916,1106,1066,1132,106,535,1445,740,1974,1226,983,73,567,1389,460,1861,1620,1828,784,392,258,1017,262,1748,271,665,20,993,1707,980,1764,1994,330,128,1253,1101,19,454,88,863,1508,1508,1844,1895,1275,937,51,318,1086,924,818,757,164,966,868,1343,1690,1891,959,1986,240,518,1646,1114,937,1410,446,742,318,1105,1009,26,1675,1296,1870,1291,1344,641,735,550,242,1512,1105,490,648,462,312,873,862,97,936,1722,1413,1266,269,682,1441,1894,1620,1623,1866,1367,1039,499,1196,480,981,311,1047,323,1056,382,1983,1958,1278,1349,1996,1346,848,1106,1163,595,526,442,1692,779,369,1177,163,607,1831,1998,839,504,1091,780,102,1331,250,155,1806,1265,1639,1716,821,1480,888,249,1810,1840,1582,1194,354,1079,993,305,1924,222,1530,231,1342,1722,1288,669,566,164,763,676,1577,969,60,1637,1895,58,563,842,420,1677,31,947,377,250,1538,1138,1506,863,1682,15,110,685,1721,1557,1298,1497,1813,1123,757,1611,969,380,1189,130,1483,423,1505,1215,452,1199,1293,1765,259,1124,1298,799,1818,553,1915,1642,319,965,1096,1799,61,18,1503,107,384,464,438,30,1773,466,1355,239,1207,96,908,558,1083,1076,1103,113,437,541,1627,560,1448,1743,1421,1497,554,1393,1348,1884,1750,1326,1046,112,825,644,857,1148,389,664,874,1263,1,320,297,1369,150,376,362,1935,116,109,966,1755,299,325,1017,1354,579,1925,482,109,372};


        int i = countLR(a, b);
        System.out.println(i);

    }

    public  static int countLR (int[] a, int[] b) {


        int length = a.length;

//        System.out.println(length);


        int totalCount = 0;


        // 先计算sum a

        Map<Integer, Integer> keyValues = new HashMap<>();


        int sumTemp= 0;

        for (int i = 0; i <length; i++) {
            sumTemp = sumTemp + a[i];
            keyValues.put(i,sumTemp);
        }

        for (int i = 0; i < length; i++) {

            int tempSum = 0;

            for (int i1 = i; i1 < length; i1++) {

                // 求和a数列中 i 到i1 的所有的和
                    tempSum = b[i] +b[i1]; // 任意两个b 数列中的和

                 int sumA = 0;

//                for (int i2 = i; i2 <= i1; i2++) {
//                    sumA = sumA + a[i2];
//
//                }


                sumA = keyValues.get(i1) - keyValues.get(i) + a[i];

                if (tempSum == sumA){


//                    System.out.println(i + " " + i1);
                    totalCount++;
                }

            }



        }


        return  totalCount;
    }

}
